package com.wyl.niupi.framework.util.exception;


import com.wyl.niupi.framework.vo.ResponseVo;
import com.wyl.niupi.frameworkExt.controller.BaseControllerExt;
import org.springframework.beans.TypeMismatchException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MultipartException;

/**
 * 捕获springmvc抛出的异常，然后自定义处理
 * @author 吴宇亮 on 2020/6/6 9:55
 */
@RestControllerAdvice
public class ControllerExceptionHander extends BaseControllerExt {

    /**
     * 参数类型不匹配
     */
    @ExceptionHandler({TypeMismatchException.class})
    public ResponseVo typeMismatchException(TypeMismatchException ex) {
        return sendFail(ex.getMessage());
    }

    /**
     * 参数不匹配问题
     */
    @ExceptionHandler({MissingServletRequestParameterException.class})
    public ResponseVo missingServletRequestParameterException(MissingServletRequestParameterException ex) {
        return sendFail(ex.getMessage());
    }

    /**
     * 超出上传文件限制大小
     */
    @ExceptionHandler(MultipartException.class)
    public ResponseVo catchException(MultipartException e) {
        return sendFail("上传文件超过大小限制！");
    }

}
